// 子应用配置列表
const subList = [
  {
    name: 'common',
    exec: false,
    alive: true,
    show: true,
    preload: true,
    url: {
      development: ':8010',
      production: '/common'
    }
  }
]
const env = process.env.NODE_ENV || 'development'
const subMap = {}
const subArr = []

// 获取子应用列表
export const hostMap = () => {
  subList.forEach((v) => {
    const { url, ...other } = v
    const info = {
      ...other,
      url: `//${window.location.hostname}${url[env]}`
    }
    subMap[v.name] = info
    subArr.push(info)
  })
  return subArr
}
// 获取子应用配置信息
export const getSubMap = (name) => {
  return subMap[name]?.show ? subMap[name] : {}
}

// 生命周期函数
export const lifecycles = {
  beforeLoad: (appWindow) => console.log(`${appWindow.__WUJIE.id} beforeLoad 生命周期`),
  beforeMount: (appWindow) => console.log(`${appWindow.__WUJIE.id} beforeMount 生命周期`),
  afterMount: (appWindow) => console.log(`${appWindow.__WUJIE.id} afterMount 生命周期`),
  beforeUnmount: (appWindow) => console.log(`${appWindow.__WUJIE.id} beforeUnmount 生命周期`),
  afterUnmount: (appWindow) => console.log(`${appWindow.__WUJIE.id} afterUnmount 生命周期`),
  activated: (appWindow) => {
    console.log(`${appWindow.__WUJIE.id} activated 生命周期`)
    appWindow.$wujie.bus.$emit('wujie-activated', {
      appId: appWindow.__WUJIE.id
    })
  },
  deactivated: (appWindow) => console.log(`${appWindow.__WUJIE.id} deactivated 生命周期`),
  loadError: (url, e) => console.log(`${url} 加载失败`, e)
}
